// hyb_yl/mysubpages/pages/search/search.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    searchCont: "",
    findArr: [],
    searchlist: [],
  },
  getSearcharr(e) {
    var that = this
    var names = e.detail.value
    that.getSearch2(names)
    app.util.request({
      'url': 'entry/wxapp/jiansuo.addsearch',
      'data': {
        openid: wx.getStorageSync('openid'),
        checkword: names,
        source: 0,
      },
      success: function (res) {
        console.log(res)
      }
    })
  },
  getSearch2: function (keywords) {
    var that = this
    //查询药品
    app.util.request({
      'url': 'entry/wxapp/jiansuo.selectshop',
      'data': {
        openid: wx.getStorageSync('openid'),
        keywords: keywords,
        source: 0,
      },
      success: function (res) {
        console.log(res)
        that.setData({
          searchlist: res.data
        })
      }
    })
  },
  getSearch: function (e) {
    var that = this
    var keywords = e.detail.value
    //查询药品
    app.util.request({
      'url': 'entry/wxapp/jiansuo.selectshop',
      'data': {
        openid: wx.getStorageSync('openid'),
        keywords: keywords,
        source: 0,
      },
      success: function (res) {
        console.log(res)
        that.setData({
          searchlist: res.data
        })
      }
    })
    this.setData({
      searchCont: e.detail.value,
    })
  },
  listitembtn(e) {
    var that = this
    console.log(e)
    var names = e.currentTarget.dataset.name
    var sid = e.currentTarget.dataset.sid
    app.util.request({
      'url': 'entry/wxapp/jiansuo.addsearch',
      'data': {
        openid: wx.getStorageSync('openid'),
        checkword: names,
        source: 0,
      },
      success: function (res) {
        console.log(res)
      }
    })
    wx.navigateTo({
      url: '../yaopindetail/yaopindetail?name=' + e.currentTarget.dataset.name + '&sid=' + sid,
    })
  },
  searchHistory: function (e) {
    console.log(e)
    this.setData({
      searchCont: e.currentTarget.dataset.item
    })
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    this.getHotsearch()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },
  doctoritem() {

    wx.navigateTo({
      url: '/hyb_yl/czhuanjiasubpages/pages/zhuanjiazhuye/zhuanjiazhuye',
    })
  },
  /**  hyb_yl/czhuanjiasubpages/pages/zhuanjiazhuye/zhuanjiazhuye
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  getHotsearch: function () {
    var that = this;
    app.util.request({
      'url': 'entry/wxapp/jiansuo.show_hotsearch',
      'data': {
        source: 0
      },
      success: function (res) {
        that.setData({
          findArr: res.data
        })
      },
    })
  },

})